// --求斐波那契数列
function fibonacci(n) {
  if (n < 2) return n;
  return fibonacci(n - 1) + fibonacci(n - 2);
}

for (let i = 0; i < 100; i++) {
  // console.log(fibonacci(i));
}

function test(a) {
  console.log(a);
  var a = 123;
  console.log(a);
  function a() {}
  console.log(a);
  var b = function b() {};
  console.log(b);
  function d() {}
}

test(1);

function test(a, b) {
  console.log(a);
  console.log(b);
  c = 0;
  var c;
  a = 3;
  b = 2;
  console.log(b);
  function b() {}
  function d() {}
  console.log(b);
}

test(4);
// AO{
//   a:4,
//   b:2,
//   c:0,
// d:function d(){}
// }

function bar() {
  return foo;
  foo = 10;
  function foo() {}
  var foo = 11;
}
console.log(bar()); //function foo(){}
console.log(bar()); //11
function bar() {
  foo = 10;
  function foo() {}
  var foo = 11;
  return foo;
}

function test() {
  var arr = [];
  for (var i = 0; i < 10; i++) {
    arr[i] = function () {
      console.log(i);
    };
  }
  return arr;
}

var myArray = test();
myArray[0]();

if (function f() {}) {
  console.log(typeof f);
}
var f = (function f() {
  return "1";
},
function g() {
  return 2;
})();

console.log(f.prototype); //2

var inherit = (function () {
  var F = function () {};
  return function (Target, Origin) {
    F.prototype = Origin.prototype;
    Target.prototype = new F();
    Target.prototype.constructor = Target;
    Target.prototype.uber = Origin.prototype;
  };
})();

function P() {}

function S() {}

inherit(S, P);
console.log(S.prototype.constructor === P);

var obj = {
  name: "123",
  age: 12,
  sayName: function () {
    console.log(this.name);
  },
};

var obj2 = Object.assign(obj);
console.log(obj2);

// var foo = 123;
// function test() {
//   this.foo = 234;
//   console.log(this.foo);
//   return function d() {};
// }
// test()();
// const l = new test();
// l();

var bar = { a: 23 };
function print() {
  bar.a = "a";
  Object.prototype.b = "b";
  return function inner() {
    console.log(bar.a);
    console.log(bar.b);
  };
}
print()();

Array.prototype.unshift = function () {
  for (let i = arguments.length - 1; i > 0; i--) {
    console.log(arguments[i]);
    this[i - 1] = arguments[i];
  }
};

function retBytes(str) {
  let len = str.length,
    count = 0;
  for (let i = 0; i < len; i++) {
    count += str.charCodeAt(i) > 255 ? 1 : 0;
  }
  return count + len;
}

console.log(retBytes("你好,bbw"));

var arr = [1, 2, 3, 4, 3, 3, 43, 4, 3];

function uniquer(arr) {
  for (let i = 0; i < arr.length - 1; i++) {
    for (let j = i + 1; j < arr.length; j++) {
      if (arr[i] == arr[j]) {
        arr.splice(j, 1);
        j--;
      }
    }
  }
}
var arr = [1, 2, 3, 4, 3, 3, 43, 4, 3];
uniquer(arr);
console.log(arr);

// function Test(name){
//   var m=100;
//   this.name=name;
//   this.say=function(){
//     console.log(this.name);
//   }
// }
// const t1=new Test("123");
// console.log(t1)

var h = function a() {
  console.log(typeof a);
};
// console.log(a);

const content = document.querySelector(".content");
console.log(content);
// let bool = false;
// let offsetX, offsetY;
// content.addEventListener("mousedown", function (e) {
//   console.log(e);
//   offsetX = e.clientX - content.offsetLeft;
//   offsetY = e.clientY - content.offsetTop;
//   bool = true;
//   e.preventDefault();
// });

// document.addEventListener("mousemove", function (e) {
//   if (bool) {
//     content.style.left = `${e.clientX - offsetX}px`;
//     content.style.top = `${e.clientY - offsetY}px`;
//   }
// });
// content.addEventListener("mouseup", function (e) {
//   bool = false;
// });

class DragElement {
  constructor(elem) {
    console.log(elem)
    this.bool = false;
    this.offsetX = 0;
    this.offsetY = 0;
    this.elem = elem;
    this.init()
  }
  init(){
    console.log(this.elem)
    this.elem.addEventListener("mousedown", this.mousedown.bind(this));
    
    document.addEventListener("mousemove", this.mousemove.bind(this));
    document.addEventListener("mouseup", this.mouseup.bind(this));
  }  
  mousedown(e){
    this.offsetX = e.clientX - this.elem.offsetLeft;
    this.offsetY = e.clientY - this.elem.offsetTop;
    this.bool = true;
    e.preventDefault();
  }
  mousemove(e){
    if (this.bool) {
      this.elem.style.left = `${e.clientX - this.offsetX}px`;
      this.elem.style.top = `${e.clientY - this.offsetY}px`;
    }
  }
  mouseup(){
    this.bool = false;
  }
}


const dragElem = new DragElement(content);
console.log(dragElem)


class RandomMove{
  constructor(elem){
    this.elem = elem;
    this.init()
  }
  init(){
    this.elem.addEventListener("mouseenter",this.move.bind(this))
  }
  move(e){
    setTimeout(() => {
      this.elem.style.left = `${Math.random()*1000}px`;
      this.elem.style.top = `${Math.random()*1000}px`;
      
    }, 350);
  }
}
const move=document.querySelector(".move");
new RandomMove(move);



document.addEventListener("keydown", function (e) {
  console.log(e);
})
document.addEventListener("keypress", function (e) {
  console.log(e);
})


const password=document.querySelector(".password");
password.addEventListener("change",function(e){
  console.log(e)
})

password.addEventListener("input",function(e){
  console.log(e)
})